package com.hqhy.like.admin.order.dao.persist.repository.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqhy.like.admin.order.dao.persist.mapper.OrderDetailsMapper;
import com.hqhy.like.admin.order.dao.persist.mapper.OrderMapper;
import com.hqhy.like.admin.order.dao.persist.repository.IOrderRepository;
import com.hqhy.like.admin.order.pojo.vo.OrderDetailsStandardVO;
import com.hqhy.like.admin.order.pojo.vo.OrderEcharts2VO;
import com.hqhy.like.admin.order.pojo.vo.OrderEchartsVO;
import com.hqhy.like.admin.order.pojo.vo.OrderListVO;
import com.hqhy.like.common.pojo.vo.PageData;
import com.hqhy.like.common.util.PageInfoToPageDataConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public class OrderRepositoryImpl implements IOrderRepository {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderDetailsMapper orderDetailsMapper;

    @Override
    public PageData<OrderListVO> listOrder(Integer pageNum, Integer pageSize) {
        //设置当前页码和每页显示的数量
        PageHelper.startPage(pageNum,pageSize);
        //调用orderMapper.selectAllOrderForAdmin()方法从数据库中获取所有订单的列表数据
        List<OrderListVO> list = orderMapper.selectAllOrderForAdmin();
        //将获取到的订单列表数据传入PageInfo构造函数，创建一个PageInfo对象
        //PageInfo是一个用于封装分页信息的类，它包含了总记录数、总页数、当前页码等信息
        PageInfo<OrderListVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    //根据订单编号查询订单
    @Override
    public OrderListVO getStandardByOrderNo(String orderNo) {
        return orderMapper.getStandardByOrderNo(orderNo);
    }

    //根据订单ID查询订单详情
    @Override
    public List<OrderDetailsStandardVO> getStandardById(Long orderId) {
        return orderDetailsMapper.getStandardById(orderId);
    }

    @Override
    public void deleteById(Long id) {
        orderMapper.deleteById(id);
    }

    @Override
    public void deleteDetailsById(Long id) {
        orderDetailsMapper.deleteDetailsById(id);
    }

    @Override
    public List<OrderEchartsVO> getOrderByDate(LocalDateTime start, LocalDateTime end) {
        return orderDetailsMapper.getOrderByDate(start,end);
    }

    @Override
    public List<OrderEcharts2VO> getEcharts(LocalDateTime start, LocalDateTime end) {
        return orderMapper.getEcharts(start,end);
    }


    @Override
    public PageData<OrderDetailsStandardVO> listOrderDetails(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderDetailsStandardVO> list = orderDetailsMapper.selectAllOrderDetailsForAdmin();
        PageInfo<OrderDetailsStandardVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);

    }


}
